-- art_manuscript
-- Created by panyl Dec/28/2016
-- 艺术手稿

require "game/ui/form/common/UIMultiSelect"

-- 初始化
function init(classId)
    -- 如果没有道具
    if ItemM.getAmount(ME.user, classId) <= 0 then
        return;
    end

    local args = PropertyM.query(classId, "args") or {};
    local statue_list = args["statue_list"];
    if not statue_list then
        return;
    end

    local optionList = {};
    local okTextList = {};
    local disableList = {};

    for i = 1, sizeof(statue_list) do
        local function okFunc()
            local ret = ArtStatueM.can_select(i, classId);
            if true ~= ret then
                if type(ret) == "string" then
                    alert(getLocStr(ret));
                end
                return;
            end
            if DungeonActionM.go("use_art_manuscript", i, classId) then
                UIMgr.getCurrentScene():removeFormByName("UIMultiSelect");
            end
        end

        table.insert(optionList, {
            ["text"] = ArtStatueM.query(statue_list[i], "name"),
            ["callback"] = okFunc,
            ["enable"] = (true == ArtStatueM.can_select(i, classId, true)),
        });
    end

    UIMgr.getCurrentScene():removeFormByName("UIMultiSelect");
    local uiMultiSelect = UIMultiSelect.create(optionList, PropertyM.query(classId, "name"),
        getLocStr("select_art_statue_desc"), {["y_offset"] = 30,});

    UIMgr.getCurrentScene():addForm(uiMultiSelect);

    return true;
end

return { init = init, };
